﻿namespace hedefgrup.reports.renault.sorting
{
    using hedefgrup.reports.renault.definitions;
    using System;
    using System.Collections.Generic;

    public class dealerListSorter : IComparer<dealerDefinition>
    {
        private dealerListSortType sortType;

        public dealerListSorter() : this(dealerListSortType.sortByCode)
        {
        }

        public dealerListSorter(dealerListSortType sortType)
        {
            this.sortType = sortType;
        }

        public int Compare(dealerDefinition x, dealerDefinition y)
        {
            if (this.sortType == dealerListSortType.sortByCode)
            {
                return (x.Equals(y) ? 0 : (x.getTypeCode().Equals("root") ? 1 : ((y.getTypeCode() == "root") ? -1 : x.getSortKey().CompareTo(y.getSortKey()))));
            }
            return (x.Equals(y) ? 0 : (x.getTypeCode().Equals("root") ? 1 : ((y.getTypeCode() == "root") ? -1 : x.getName().CompareTo(y.getName()))));
        }
    }
}

